/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ControlDeAcompanantes.java
 *
 * Created on 23/06/2010, 09:17:14 PM
 */

package CapaGrafica;
import CapaLogica.ManejoAcompanantes;
/**
 *
 * @author Maria
 */
public class ControlDeAcompanantes extends javax.swing.JFrame {

    private ManejoAcompanantes acompanantes;
    private AgregarAcompanante ventanaMadre;
    /** Creates new form ControlDeAcompanantes */
    public ControlDeAcompanantes(AgregarAcompanante ventanaMadre, String cedulaCliente, String idReserva) {
        this.ventanaMadre  = ventanaMadre;
        this.acompanantes = new ManejoAcompanantes(cedulaCliente, idReserva);
        initComponents();
        this.jLacompanantes = acompanantes.refrescarLista(jLacompanantes);
    }
    ControlDeAcompanantes(AgregarAcompanante ventanaMadre, ManejoAcompanantes acompanantes)
    {
        initComponents();

        this.acompanantes = acompanantes;
        this.jLacompanantes = acompanantes.refrescarLista(jLacompanantes);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBlisto = new javax.swing.JButton();
        jBcancelar = new javax.swing.JButton();
        jBagregar = new javax.swing.JButton();
        jBeliminar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jLacompanantes = new javax.swing.JList();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        setLocationByPlatform(true);

        jBlisto.setText("listo");
        jBlisto.setName("jBlisto"); // NOI18N
        jBlisto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBlistoActionPerformed(evt);
            }
        });

        jBcancelar.setText("Cancelar");
        jBcancelar.setName("jBcancelar"); // NOI18N
        jBcancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcancelarActionPerformed(evt);
            }
        });

        jBagregar.setText("Agregar");
        jBagregar.setName("jBagregar"); // NOI18N
        jBagregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBagregarActionPerformed(evt);
            }
        });

        jBeliminar.setText("Eliminar");
        jBeliminar.setName("jBeliminar"); // NOI18N
        jBeliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBeliminarActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jLacompanantes.setName("jLacompanantes"); // NOI18N
        jScrollPane2.setViewportView(jLacompanantes);

        jSeparator1.setName("jSeparator1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jBcancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBagregar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBlisto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBeliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                .addGap(69, 69, 69))
            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 433, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBagregar)
                    .addComponent(jBeliminar))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBcancelar)
                    .addComponent(jBlisto))
                .addGap(23, 23, 23))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBcancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcancelarActionPerformed
    ventanaMadre.setVisible(true);
        this.dispose();
    // TODO add your handling code here:
    }//GEN-LAST:event_jBcancelarActionPerformed

    private void jBlistoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBlistoActionPerformed
       acompanantes.enviarInformacion();
        ventanaMadre.imprimirFactura();
        this.setVisible(false); // TODO add your handling code here:
    }//GEN-LAST:event_jBlistoActionPerformed

    private void jBagregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBagregarActionPerformed
       FormularioAcompanante ventana = new FormularioAcompanante(ventanaMadre, acompanantes);
        this.setVisible(false);
        ventana.setVisible(true); // TODO add your handling code here:
    }//GEN-LAST:event_jBagregarActionPerformed

    private void jBeliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBeliminarActionPerformed
       int i = jLacompanantes.getSelectedIndex();
        acompanantes.eliminar(i);
        ControlDeAcompanantes ventana = new ControlDeAcompanantes(ventanaMadre, acompanantes);
        ventana.setVisible(true);
        this.dispose(); // TODO add your handling code here:
    }//GEN-LAST:event_jBeliminarActionPerformed

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBagregar;
    private javax.swing.JButton jBcancelar;
    private javax.swing.JButton jBeliminar;
    private javax.swing.JButton jBlisto;
    private javax.swing.JList jLacompanantes;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
